//deprecated
//not sure, but i dont really think this is how i want to store the data


package mainWindowSupport;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JMenuItem;

public class MenuItem implements ActionListener{
	
	private AbstractButton me;
	private String myText = "";
	private String imgName = "";
	private String actionCommand = "";
	private boolean isToolbar = false; 
	
	
	//creates an instance of a menu item
	public MenuItem(String text, String loc, String cmd, boolean tool){
		
		myText = text;
		imgName = loc;
		actionCommand = cmd;
		isToolbar = tool;
		
		//make into a tool bar button
		if (isToolbar) {
			makeToolbarButton();
		}
		//make into a menu item
		else {
			makeCascadingItem();
		}
		
	}
	
	//makes a tool bar menu item to be added into the tool bar
	private void makeToolbarButton() {
		
		me = new JButton();
		
		//Look for the image
        String imgLocation = "images/" + imgName + ".gif";
        URL imageURL = ToolBar.class.getResource(imgLocation);

        //Create and initialize the button
        //JButton button = new JButton();
        me.setActionCommand(actionCommand);
        me.addActionListener(this);

        if (imageURL != null) {                      //image found
            me.setIcon(new ImageIcon(imageURL, myText));
        } else {                                     //no image found
            me.setText(myText);
            System.err.println("Resource not found: " + imgLocation);
        }
		
	}
	
	//Makes a cascading menu item to be added to the menu bar
	private void makeCascadingItem() {
		
		me = new JMenuItem(myText);
		me.setActionCommand(actionCommand);
		me.addActionListener(this);
		
	}
	
	
	@Override
	public void actionPerformed(ActionEvent e) {
		
		System.out.println(actionCommand);
		//
	}
	
	//returns the cascading menu or tool bar button to be added wherever
	public AbstractButton getItem() {
		return me;
	}
}
